#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
	pid_t id = fork();
	if(id < 0)
	{
		perror("fork");
		return 1;
	}
	else if(id == 0)
	{
		printf("i am child process\n");
		sleep(5);
	}
	else
	{
		int status = 0;
		pid_t ret = waitpid(-1, &status, 0);
		printf("this is test for wait\n");
		if(WIFEXITED(status) && ret == id)
		{
 			printf("wait child 5s success, child return code is :%d\n",WEXITSTATUS(status));
 		}
 		else
 		{
 			printf("wait child failed, return.\n");
 			return 1;
 		}
	}
	
	return 0;





	//execlp("ls", "ps", "-la", NULL);
	//exit(0);
}
